//抽象工厂模式
interface IProductA { }
interface IProductB { }

class Product1A implements IProductA { }
class Product1B implements IProductB { }
class Product2A implements IProductA { }
class Product2B implements IProductB { }

public abstract class AbstractFactory
{
    public static void main(String[] args) {
        System.out.println(AbstractFactory.chooseFactory(1).getProductA());
        System.out.println(AbstractFactory.chooseFactory(1).getProductB());
        System.out.println(AbstractFactory.chooseFactory(2).getProductA());
        System.out.println(AbstractFactory.chooseFactory(2).getProductB());
    }
	public static AbstractFactory chooseFactory(int factoryName)
	{
		switch (factoryName)
		{
			case 1: return new Factory1();
			case 2: return new Factory2();
			default: return null;
		}
	}
	public abstract IProductA getProductA();
	public abstract IProductB getProductB();
}

class Factory1 extends AbstractFactory
{
    @Override
	public IProductA getProductA() { return new Product1A();}
    @Override
    public IProductB getProductB() { return new Product1B();}
}
class Factory2 extends AbstractFactory
{
    @Override
    public IProductA getProductA() { return new Product2A(); }
    @Override
	public IProductB getProductB() { return new Product2B(); }
}